package org.jeecg.modules.uwms;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.util.DateUtils;
import org.jeecg.common.util.RedisUtil;
import org.jeecg.modules.baseUtil.QRcodeUtil;
import org.jeecg.modules.baseUtil.SapRFC;
import org.jeecg.modules.baseUtil.StringUtil;
import org.jeecg.modules.wdkj.entity.WdkjBaseGb2312;
import org.jeecg.modules.wdkj.service.impl.WdkjBaseGb2312ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.*;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;


/**
 * @Description: 测试demo
 * @Author: zhaodui
 * @Date:2018-12-29
 * @Version:V1.0
 */
@Slf4j
@Api(tags="UWMS")
@RestController
@RequestMapping("/uwms/client")
public class UwmsClientController  {
    @Value("${jeecg.path.upload}")
    private String upLoadPath;

    @Autowired
    private RedisUtil redisUtil;

    @Autowired
    private WdkjBaseGb2312ServiceImpl wdkjBaseGb2312Service;
    @Value("${hana.sap_hana}")
    private String  sap_hana ;
    @Value("${hana.sap_user}")
    private String  sap_user  ;
    @Value("${hana.sap_password}")
    private String  sap_password ;


    @Value("${saprfc.clientName}")
    public  String clientName   ;

    @Value("${saprfc.userid}")
    public  String  userid    ;

    @Value("${saprfc.password}")
    public  String  password    ;

    @Value("${saprfc.language}")
    public  String  language     ;

    @Value("${saprfc.host}")
    public  String  host     ;

    @Value("${saprfc.system}")
    public  String  system   ;
//U型理货REDIS数据
    /**
     * 添加
     *
     * @param jeecgDemo
     * @return
     */
    @PostMapping(value = "/senddata")
    @AutoLog(value = "发送数据")
    @ApiOperation(value = "发送数据", notes = "发送数据")
    public Result<?> senddata(@RequestBody Uwmsdata jeecgDemo) {
        Result<Uwmsdata> result = new Result<Uwmsdata>();
        try {
            //2 序列   1命令 3 标签 3 数据
            String out04 = jeecgDemo.getData04();
            StringBuffer out04buf = new StringBuffer();
            if("35".equals(jeecgDemo.getData01())){
                String a=jeecgDemo.getData04();
                if(a.length()>25){
                    a = a.substring(0,25);
                };
                String showstr= com.zhaodui.fxy.StringUtil.leftPad(a,25,'―');
                try {
                    List<String> list= Stream.iterate(0, n -> ++n).limit(showstr.length())

                            .map(n -> "" + showstr.charAt(n))

                            .collect(Collectors.toList());
                    for(String str:list){
                        byte[] b=str.getBytes("GB2312");
                        String gb2312 = bytesToHexFun1(b);
                        if(gb2312.length()<=2){
                            WdkjBaseGb2312 wdkjBaseGb2312 = wdkjBaseGb2312Service.getbywdkj01(str);
                            if(wdkjBaseGb2312!=null){
                                if(StringUtil.isEmpty(wdkjBaseGb2312.getWdkj03())){
                                    out04buf.append("A2A0");
                                }else{
                                    out04buf.append(wdkjBaseGb2312.getWdkj03());
                                }
                            }else{
                                wdkjBaseGb2312 = new WdkjBaseGb2312();
                                wdkjBaseGb2312.setWdkj01(str);
                                wdkjBaseGb2312.setWdkj02(gb2312);
                                wdkjBaseGb2312Service.save(wdkjBaseGb2312);
                                out04buf.append("A2A0");
                            }
                        }else{//转换成功
                            out04buf.append(gb2312);
                        }
                    }
                } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();
                }
                out04 = out04buf.toString();

            }else{
                out04 = jeecgDemo.getData04();
            }
            //转换完成
            //out04
            redisUtil.set(jeecgDemo.getData02(), jeecgDemo.getData01()+jeecgDemo.getData03()+out04);
            result.success("发送数据成功！"+jeecgDemo.getData01()+jeecgDemo.getData03()+out04);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            result.error500("操作失败");
        }
        return result;
    }
    /**
     * 添加
     *
     * @return
     */
    @GetMapping(value = "/getdata")
    @AutoLog(value = "get")
    @ApiOperation(value = "发送数据", notes = "发送数据")
    public Result<?> gettest(@RequestParam  String indata) {
        Result<Uwmsdata> result = new Result<Uwmsdata>();
        try {
            SapRFC.clientName = clientName;
            SapRFC.userid = userid;
            SapRFC.password = password;
            SapRFC.language = language;
            SapRFC.system = system;
            SapRFC.host = host;
            SapRFC.clientName = clientName;
            SapRFC saprfc = SapRFC.getInstance();

//			saprfc.setpara(clientName,userid,password,language,host,system);
//			SapRFC.get();
//			hanautil hana  = new hanautil();
//			hana.setPara(sap_hana,sap_user,sap_password);
//			String resultstr = hana.getlqua(indata);
//			redisUtil.set(indata, indata);
//			result.success(resultstr);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            result.error500("操作失败");
        }
        return result;
    }



    /**
     * 添加
     *
     * @param jeecgDemo
     * @return
     */
    @PostMapping(value = "/receivedata")
    @AutoLog(value = "接收数据")
    @ApiOperation(value = "接收数据", notes = "接收数据")
    public Result<?> receivedata(@RequestBody Uwmsdata jeecgDemo) {
        Result<Uwmsdata> result = new Result<Uwmsdata>();
        try {
//			redisUtil.set(jeecgDemo.getData02(), jeecgDemo.getData01()+jeecgDemo.getData03()+jeecgDemo.getData04());
            result.success("发送数据成功！");
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            result.error500("操作失败");
        }
        return result;
    }
    //电商退货标签
    @RequestMapping(value = "/print/bq/{username}", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    @ApiOperation(value = "根据vbeln1生成合同", notes = "vbeln1", httpMethod = "POST", produces = "application/json")
    public Result<?> batchdownbq(@PathVariable("username") String username,
                                 @RequestBody printheader printheaderobj) {
        Result<Uwmsdata> result = new Result<Uwmsdata>();
        OutputStream fileOut = null;
        BufferedImage bufferImg = null;

        ByteArrayOutputStream byteArrayOut = new ByteArrayOutputStream();
        HSSFWorkbook wb = new HSSFWorkbook();
        CellStyle cs = wb.createCellStyle();
        CellStyle cs1 = wb.createCellStyle();
        CellStyle cs2 = wb.createCellStyle();

        // 创建两种字体
        Font f = wb.createFont();
        Font f1 = wb.createFont();
        Font f2 = wb.createFont();

        // 创建第一种字体样式（用于列名）
        f.setFontHeightInPoints((short) 12);
        f.setColor(IndexedColors.BLACK.getIndex());
//				f.setBoldweight(Font.BOLDWEIGHT_BOLD);
// 创建两种字体

        // 创建第一种字体样式（用于列名）
        f1.setFontHeightInPoints((short) 8);
        f1.setColor(IndexedColors.BLACK.getIndex());
//				f1.setBoldweight(Font.BOLDWEIGHT_BOLD);

        f2.setFontHeightInPoints((short) 10);
        f2.setColor(IndexedColors.BLACK.getIndex());
        // 设置第一种单元格的样式（用于列名）
        cs.setFont(f);
        cs.setBorderLeft(CellStyle.BORDER_NONE);
        cs.setBorderRight(CellStyle.BORDER_NONE);
        cs.setBorderTop(CellStyle.BORDER_NONE);
        cs.setBorderBottom(CellStyle.BORDER_NONE);
        cs.setAlignment(HSSFCellStyle.ALIGN_LEFT);
        cs1.setFont(f1);
        cs1.setBorderLeft(CellStyle.BORDER_THIN);
        cs1.setBorderRight(CellStyle.BORDER_THIN);
        cs1.setBorderTop(CellStyle.BORDER_THIN);
        cs1.setBorderBottom(CellStyle.BORDER_THIN);
        cs1.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        cs1.setWrapText(true);
        cs2.setFont(f2);
        cs2.setBorderLeft(CellStyle.BORDER_NONE);
        cs2.setBorderRight(CellStyle.BORDER_NONE);
        cs2.setBorderTop(CellStyle.BORDER_NONE);
        cs2.setBorderBottom(CellStyle.BORDER_NONE);
        cs2.setAlignment(HSSFCellStyle.ALIGN_LEFT);
        cs2.setWrapText(true);


        HSSFSheet sheet = wb.createSheet("打印");

        sheet.setMargin(HSSFSheet.TopMargin, 0.1);// 页边距（上）
        sheet.setMargin(HSSFSheet.BottomMargin, 0.1);// 页边距（下）
        sheet.setMargin(HSSFSheet.LeftMargin, 0.1);// 页边距（左）
        sheet.setMargin(HSSFSheet.RightMargin, 0.1);// 页边距（右
        sheet.setColumnWidth(0, 3 * 256);
        sheet.setColumnWidth(1, 18 * 256);
        sheet.setColumnWidth(2, 10 * 256);
        sheet.setColumnWidth(3, 20 * 200);

        HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
        HSSFClientAnchor anchor = null;

        int cellsNum = 0;
        int pagesize = 1;
        int page = 0;
        short high = 300;
        List<printitem> listitem = printheaderobj.getPrintitem();
        cellsNum++;
        Row rowColumnValue5 = sheet.createRow((short) page * pagesize + cellsNum); // 列名
        Cell cell6 = rowColumnValue5.createCell(0);
        cell6.setCellValue("");
        CellRangeAddress c6 = new CellRangeAddress(page * pagesize + cellsNum, page * pagesize + cellsNum, 0, 3);
        for (printitem t : listitem) {
            Row rowColumnValue = sheet.createRow((short) page * pagesize + cellsNum); // 列名
            rowColumnValue.setHeight((short) high);
            Cell cell1 = rowColumnValue.createCell(1);
            cell1.setCellValue(t.getData01());
            cell1.setCellStyle(cs1);
            rowColumnValue.setHeight((short) high);
            Cell cell2 = rowColumnValue.createCell(2);
            cell2.setCellValue(t.getData02());
            cell2.setCellStyle(cs1);
            rowColumnValue.setHeight((short) high);
            Cell cell13 = rowColumnValue.createCell(3);
            cell13.setCellValue(t.getData03());
            cell13.setCellStyle(cs1);
            cellsNum++;
        }

        try {
            // 第七步，将文件存到指定位置并打印
            String filest = DateUtils.date2Str(DateUtils.yyyymmddhhmmss);
            String savaPath = upLoadPath;
            String fileurl = "wlbq" + username + "/" + filest + "/"+ filest + ".xls";

            File file = new File(savaPath + "/" + "wlbq" + username + "/" + filest);
            savaPath = savaPath.replace("D:/","D:/");

            if (!file.exists()) {
                file.mkdirs();// 创建文件根目录
            }
            String outfilePath = savaPath + "/" + fileurl;
            try {
                FileOutputStream fileOutputStream = new FileOutputStream(outfilePath);//指定路径与名字和格式
                wb.write(fileOutputStream);//将数据写出去
                fileOutputStream.close();//关闭输出流
                printUtil.printfile(outfilePath);
            } catch (Exception e) {
                e.printStackTrace();
            }
            System.out.println("----Excle文件已生成------");
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (fileOut != null) {
                try {
                    fileOut.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return result;
    }
    //u型理货盒码
    @RequestMapping(value = "/print/hm/{username}", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    @ApiOperation(value = "根据vbeln1生成合同", notes = "vbeln1", httpMethod = "POST", produces = "application/json")
    public Result<?> batchdownhm(@PathVariable("username") String username,
                                 @RequestBody printheader printheaderobj) {
        Result<Uwmsdata> result = new Result<Uwmsdata>();
        OutputStream fileOut = null;
        BufferedImage bufferImg = null;

        ByteArrayOutputStream byteArrayOut = new ByteArrayOutputStream();
        String url = upLoadPath +"/excelmodel/hm.xls";
        url = url.replace("D:/","D:/");

        HSSFWorkbook wb  = null;
        try {
            wb = new HSSFWorkbook(new FileInputStream(url));
        } catch (IOException e) {
            e.printStackTrace();
        }
        CellStyle cs = wb.createCellStyle();
        CellStyle cs1 = wb.createCellStyle();
        CellStyle cs2 = wb.createCellStyle();

        // 创建两种字体
        Font f = wb.createFont();
        Font f1 = wb.createFont();
        Font f2 = wb.createFont();

        // 创建第一种字体样式（用于列名）
        f.setFontHeightInPoints((short) 10);
        f.setColor(IndexedColors.BLACK.getIndex());
//				f.setBoldweight(Font.BOLDWEIGHT_BOLD);
// 创建两种字体

        // 创建第一种字体样式（用于列名）
        f1.setFontHeightInPoints((short) 14);
        f1.setColor(IndexedColors.BLACK.getIndex());
//				f1.setBoldweight(Font.BOLDWEIGHT_BOLD);

        f2.setFontHeightInPoints((short) 10);
        f2.setColor(IndexedColors.BLACK.getIndex());
        // 设置第一种单元格的样式（用于列名）
        cs.setFont(f);
        cs.setBorderLeft(CellStyle.BORDER_NONE);
        cs.setBorderRight(CellStyle.BORDER_NONE);
        cs.setBorderTop(CellStyle.BORDER_NONE);
        cs.setBorderBottom(CellStyle.BORDER_NONE);
        cs.setAlignment(HSSFCellStyle.ALIGN_LEFT);
        cs1.setFont(f1);
        cs1.setBorderLeft(CellStyle.BORDER_NONE);
        cs1.setBorderRight(CellStyle.BORDER_NONE);
        cs1.setBorderTop(CellStyle.BORDER_NONE);
        cs1.setBorderBottom(CellStyle.BORDER_NONE);
        cs1.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        cs1.setWrapText(true);
        cs2.setFont(f2);
        cs2.setBorderLeft(CellStyle.BORDER_NONE);
        cs2.setBorderRight(CellStyle.BORDER_NONE);
        cs2.setBorderTop(CellStyle.BORDER_NONE);
        cs2.setBorderBottom(CellStyle.BORDER_NONE);
        cs2.setAlignment(HSSFCellStyle.ALIGN_LEFT);
        cs2.setWrapText(true);


        HSSFSheet sheet = wb.getSheetAt(0);

//		sheet.setMargin(HSSFSheet.TopMargin, 0);// 页边距（上）
//		sheet.setMargin(HSSFSheet.BottomMargin, 0);// 页边距（下）
//		sheet.setMargin(HSSFSheet.LeftMargin, 0.2);// 页边距（左）
//		sheet.setMargin(HSSFSheet.RightMargin, 0);// 页边距（右
//		sheet.setColumnWidth(0, 5 * 256);
//		sheet.setColumnWidth(1, 7 * 256);
//		sheet.setColumnWidth(2, 15 * 256);
//		sheet.setColumnWidth(3, 25 * 200);

        HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
        HSSFClientAnchor anchor = null;

        int cellsNum = 0;
        int pagesize = 1;
        int page = 0;
        short high = 600;
        List<printitem> listitem = printheaderobj.getPrintitem();
//		Row rowColumnValue5 = sheet.createRow((short) page * pagesize + cellsNum); // 列名
//		Cell cell6 = rowColumnValue5.createCell(0);
//		cell6.setCellValue("");
//		CellRangeAddress c6 = new CellRangeAddress(page * pagesize + cellsNum, page * pagesize + cellsNum, 0, 3);
        for (printitem t : listitem) {
            cellsNum++;
            Row rowColumnValue = sheet.createRow((short) page * pagesize + cellsNum); // 列名
            rowColumnValue.setHeight((short) high);
            Cell cell1 = rowColumnValue.createCell(1);
            cell1.setCellValue(t.getData01());
            cell1.setCellStyle(cs1);
            rowColumnValue.setHeight((short) high);
            Cell cell2 = rowColumnValue.createCell(2);
            cell2.setCellValue(t.getData02());
            cell2.setCellStyle(cs1);
//			rowColumnValue.setHeight((short) high);
//			Cell cell13 = rowColumnValue.createCell(3);
//			cell13.setCellValue(t.getData03());
//			cell13.setCellStyle(cs1);
        }

        try {
            // 第七步，将文件存到指定位置并打印
            String filest = DateUtils.date2Str(DateUtils.yyyymmddhhmmss);
            String savaPath = upLoadPath;
            String fileurl = "hmbq" + username + "/" + filest + "/"+ filest + ".xls";

            File file = new File(savaPath + "/" + "hmbq" + username + "/" + filest);
            savaPath = savaPath.replace("D:/","D:/");

            if (!file.exists()) {
                file.mkdirs();// 创建文件根目录
            }
            String outfilePath = savaPath + "/" + fileurl;
            try {
                FileOutputStream fileOutputStream = new FileOutputStream(outfilePath);//指定路径与名字和格式
                wb.write(fileOutputStream);//将数据写出去
                fileOutputStream.close();//关闭输出流
                printUtil.printfile(outfilePath);
            } catch (Exception e) {
                e.printStackTrace();
            }
            System.out.println("----Excle文件已生成------");
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (fileOut != null) {
                try {
                    fileOut.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return result;
    }


    //u型理货盒码
    @RequestMapping(value = "/print/gxtm/{username}", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    @ApiOperation(value = "根据vbeln1生成合同", notes = "vbeln1", httpMethod = "POST", produces = "application/json")
    public Result<?> batchgxtm(@PathVariable("username") String username,
                                 @RequestBody printheader printheaderobj) {
        Result<Uwmsdata> result = new Result<Uwmsdata>();
        OutputStream fileOut = null;
        BufferedImage bufferImg = null;

        ByteArrayOutputStream byteArrayOut = new ByteArrayOutputStream();
        String url = upLoadPath +"/excelmodel/gxtm.xls";
        url = url.replace("D:/","D:/");

        HSSFWorkbook wb  = null;
        try {
            wb = new HSSFWorkbook(new FileInputStream(url));
        } catch (IOException e) {
            e.printStackTrace();
        }
        CellStyle cs = wb.createCellStyle();
        CellStyle cs1 = wb.createCellStyle();
        CellStyle cs2 = wb.createCellStyle();

        // 创建两种字体
        Font f = wb.createFont();
        Font f1 = wb.createFont();
        Font f2 = wb.createFont();

        // 创建第一种字体样式（用于列名）
        f.setFontHeightInPoints((short) 10);
        f.setColor(IndexedColors.BLACK.getIndex());
//				f.setBoldweight(Font.BOLDWEIGHT_BOLD);
// 创建两种字体

        // 创建第一种字体样式（用于列名）
        f1.setFontHeightInPoints((short) 14);
        f1.setColor(IndexedColors.BLACK.getIndex());
//				f1.setBoldweight(Font.BOLDWEIGHT_BOLD);

        f2.setFontHeightInPoints((short) 10);
        f2.setColor(IndexedColors.BLACK.getIndex());
        // 设置第一种单元格的样式（用于列名）
        cs.setFont(f);
        cs.setBorderLeft(CellStyle.BORDER_NONE);
        cs.setBorderRight(CellStyle.BORDER_NONE);
        cs.setBorderTop(CellStyle.BORDER_NONE);
        cs.setBorderBottom(CellStyle.BORDER_NONE);
        cs.setAlignment(HSSFCellStyle.ALIGN_LEFT);
        cs1.setFont(f1);
        cs1.setBorderLeft(CellStyle.BORDER_NONE);
        cs1.setBorderRight(CellStyle.BORDER_NONE);
        cs1.setBorderTop(CellStyle.BORDER_NONE);
        cs1.setBorderBottom(CellStyle.BORDER_NONE);
        cs1.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        cs1.setWrapText(true);
        cs2.setFont(f2);
        cs2.setBorderLeft(CellStyle.BORDER_NONE);
        cs2.setBorderRight(CellStyle.BORDER_NONE);
        cs2.setBorderTop(CellStyle.BORDER_NONE);
        cs2.setBorderBottom(CellStyle.BORDER_NONE);
        cs2.setAlignment(HSSFCellStyle.ALIGN_LEFT);
        cs2.setWrapText(true);


        HSSFSheet sheet = wb.getSheetAt(0);

//		sheet.setMargin(HSSFSheet.TopMargin, 0);// 页边距（上）
//		sheet.setMargin(HSSFSheet.BottomMargin, 0);// 页边距（下）
//		sheet.setMargin(HSSFSheet.LeftMargin, 0.2);// 页边距（左）
//		sheet.setMargin(HSSFSheet.RightMargin, 0);// 页边距（右
//		sheet.setColumnWidth(0, 5 * 256);
//		sheet.setColumnWidth(1, 7 * 256);
//		sheet.setColumnWidth(2, 15 * 256);
//		sheet.setColumnWidth(3, 25 * 200);

        HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
        HSSFClientAnchor anchor = null;

        int cellsNum = 0;
        int pagesize = 1;
        int page = 0;
        short high = 600;
        List<printitem> listitem = printheaderobj.getPrintitem();
//		Row rowColumnValue5 = sheet.createRow((short) page * pagesize + cellsNum); // 列名
//		Cell cell6 = rowColumnValue5.createCell(0);
//		cell6.setCellValue("");
//		CellRangeAddress c6 = new CellRangeAddress(page * pagesize + cellsNum, page * pagesize + cellsNum, 0, 3);
        for (printitem t : listitem) {
            cellsNum++;
            Row rowColumnValue = sheet.createRow((short) page * pagesize + cellsNum); // 列名
            rowColumnValue.setHeight((short) high);
            Cell cell1 = rowColumnValue.createCell(1);
            cell1.setCellValue(t.getData01());
            cell1.setCellStyle(cs1);
            rowColumnValue.setHeight((short) high);
            Cell cell2 = rowColumnValue.createCell(2);
            cell2.setCellValue(t.getData02());
            cell2.setCellStyle(cs1);
//			rowColumnValue.setHeight((short) high);
//			Cell cell13 = rowColumnValue.createCell(3);
//			cell13.setCellValue(t.getData03());
//			cell13.setCellStyle(cs1);
        }

        try {
            // 第七步，将文件存到指定位置并打印
            String filest = DateUtils.date2Str(DateUtils.yyyymmddhhmmss);
            String savaPath = upLoadPath;
            String fileurl = "hmbq" + username + "/" + filest + "/"+ filest + ".xls";

            File file = new File(savaPath + "/" + "hmbq" + username + "/" + filest);
            savaPath = savaPath.replace("D:/","D:/");

            if (!file.exists()) {
                file.mkdirs();// 创建文件根目录
            }
            String outfilePath = savaPath + "/" + fileurl;
            try {
                FileOutputStream fileOutputStream = new FileOutputStream(outfilePath);//指定路径与名字和格式
                wb.write(fileOutputStream);//将数据写出去
                fileOutputStream.close();//关闭输出流
                printUtil.printfile(outfilePath);
            } catch (Exception e) {
                e.printStackTrace();
            }
            System.out.println("----Excle文件已生成------");
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (fileOut != null) {
                try {
                    fileOut.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return result;
    }

    //u型理货盒码
    @RequestMapping(value = "/print/gylc/{username}", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    @ApiOperation(value = "根据vbeln1生成合同", notes = "vbeln1", httpMethod = "POST", produces = "application/json")
    public Result<?> batchdowngylc(@PathVariable("username") String username,
                                   @RequestBody printheader printheaderobj) {
        Result<Uwmsdata> result = new Result<Uwmsdata>();
        OutputStream fileOut = null;
        BufferedImage bufferImg = null;


        ByteArrayOutputStream byteArrayOut = new ByteArrayOutputStream();
        String url = upLoadPath +"/excelmodel/gylck.xls";
        url = url.replace("D:/","D:/");

        HSSFWorkbook wb  = null;
        try {
            wb = new HSSFWorkbook(new FileInputStream(url));
        } catch (IOException e) {
            e.printStackTrace();
        }
        CellStyle cs = wb.createCellStyle();
        CellStyle cs1 = wb.createCellStyle();
        CellStyle cs2 = wb.createCellStyle();

        // 创建两种字体
        Font f = wb.createFont();
        Font f1 = wb.createFont();
        Font f2 = wb.createFont();

        // 创建第一种字体样式（用于列名）
        f.setFontHeightInPoints((short) 10);
        f.setColor(IndexedColors.BLACK.getIndex());
//				f.setBoldweight(Font.BOLDWEIGHT_BOLD);
// 创建两种字体

        // 创建第一种字体样式（用于列名）
        f1.setFontHeightInPoints((short) 14);
        f1.setColor(IndexedColors.BLACK.getIndex());
//				f1.setBoldweight(Font.BOLDWEIGHT_BOLD);

        f2.setFontHeightInPoints((short) 10);
//		f2.setColor(IndexedColors.BLACK.getIndex());
        // 设置第一种单元格的样式（用于列名）
        cs.setFont(f);
        cs.setBorderLeft(CellStyle.BORDER_NONE);
        cs.setBorderRight(CellStyle.BORDER_NONE);
        cs.setBorderTop(CellStyle.BORDER_NONE);
        cs.setBorderBottom(CellStyle.BORDER_NONE);
        cs.setAlignment(HSSFCellStyle.ALIGN_LEFT);
        cs1.setFont(f2);
        cs1.setBorderLeft(CellStyle.BORDER_THIN);
        cs1.setBorderRight(CellStyle.BORDER_THIN);
        cs1.setBorderTop(CellStyle.BORDER_THIN);
        cs1.setBorderBottom(CellStyle.BORDER_THIN);
        cs1.setAlignment(HSSFCellStyle.BORDER_THIN);
        cs1.setWrapText(true);
        cs2.setFont(f2);
        cs2.setBorderLeft(CellStyle.BORDER_NONE);
        cs2.setBorderRight(CellStyle.BORDER_NONE);
        cs2.setBorderTop(CellStyle.BORDER_NONE);
        cs2.setBorderBottom(CellStyle.BORDER_NONE);
        cs2.setAlignment(HSSFCellStyle.ALIGN_LEFT);
        cs2.setWrapText(true);


        HSSFSheet sheet = wb.getSheetAt(0);
        try{
            bufferImg = QRcodeUtil.createImage(printheaderobj.getData08());
            ImageIO.write(bufferImg, "jpg", byteArrayOut);
        }catch (Exception e){

        }
        //				//画图的顶级管理器，一个sheet只能获取一个（一定要注意这点）
        HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
        //anchor主要用于设置图片的属性
        HSSFClientAnchor anchor = new HSSFClientAnchor(15, 15, 0, 0,(short) 11, 0, (short) 13, 2);
        anchor.setAnchorType(3);
        //插入图片
        patriarch.createPicture(anchor, wb.addPicture(byteArrayOut.toByteArray(), HSSFWorkbook.PICTURE_TYPE_JPEG));



//		sheet.setMargin(HSSFSheet.TopMargin, 0);// 页边距（上）
//		sheet.setMargin(HSSFSheet.BottomMargin, 0);// 页边距（下）
//		sheet.setMargin(HSSFSheet.LeftMargin, 0.2);// 页边距（左）
//		sheet.setMargin(HSSFSheet.RightMargin, 0);// 页边距（右
//		sheet.setColumnWidth(0, 5 * 256);
//		sheet.setColumnWidth(1, 7 * 256);
//		sheet.setColumnWidth(2, 15 * 256);
//		sheet.setColumnWidth(3, 25 * 200);



        int cellsNum = 4;
        int pagesize = 1;
        int page = 0;
        short high = 600;
        List<printitem> listitem = printheaderobj.getPrintitem();
        Row rowColumnValue5 = sheet.getRow((short) 3); // 列名
        Cell cellh1 = rowColumnValue5.getCell(0);

        cellh1.setCellValue(StringUtil.replaceBfore(printheaderobj.getData01()));
        Cell cellh2 = rowColumnValue5.getCell(1);
        cellh2.setCellValue(printheaderobj.getData02());
        Cell cellh3 = rowColumnValue5.getCell(2);
        cellh3.setCellValue(printheaderobj.getData03());

        Cell cellh4 = rowColumnValue5.getCell(3);
        cellh4.setCellValue(printheaderobj.getData04());


        Cell cellh5 = rowColumnValue5.getCell(11);
        cellh5.setCellValue(printheaderobj.getData05());
        Cell cellh6 = rowColumnValue5.getCell(13);
        cellh6.setCellValue(printheaderobj.getData06());

        Cell cellh7 = rowColumnValue5.getCell(8);
        cellh7.setCellValue(printheaderobj.getData09());

        Cell cellh8 = rowColumnValue5.getCell(15);
        cellh8.setCellValue(StringUtil.replaceBfore(printheaderobj.getData01())+"-"+printheaderobj.getData10());//子单号

        Row rowColumnValue6 = sheet.getRow((short) 0); // 列名
        Cell cellhead = rowColumnValue6.getCell(13);
        cellhead.setCellValue("图纸编号："+printheaderobj.getData07());
        Row rowColumnValue3 = sheet.getRow((short) 2); // 列名
        Cell cellhead3 = rowColumnValue3.getCell(20);
        if(StringUtil.isEmpty(printheaderobj.getData11())){
            cellhead3.setCellValue("请确认领料");
        }else{
            cellhead3.setCellValue(printheaderobj.getData11());
        }

        Row rowColumnValue4 = sheet.getRow((short) 3); // 列名
        Cell cellhead4 = rowColumnValue4.getCell(20);
        cellhead4.setCellValue(printheaderobj.getData12());//组别

        Row rowColumnValue7 = sheet.getRow((short) 5); // 列名
        Cell cellhead7= rowColumnValue7.getCell(4);
        cellhead7.setCellValue(printheaderobj.getData13());//天数

        Row rowColumnValuelast = sheet.getRow((short) 47); // 列名

        Cell cellheadzdr= rowColumnValuelast.getCell(7);
        cellheadzdr.setCellValue("制单人："+printheaderobj.getData14());//制单人

        Cell cellheaddayin= rowColumnValuelast.getCell(15);
        cellheaddayin.setCellValue(printheaderobj.getData15());//打印时间


        for (printitem t : listitem) {
            cellsNum++;

            Row rowColumnValue = sheet.getRow((short) page * pagesize + cellsNum); // 列名
//			rowColumnValue.setHeight((short) high);
            Cell cell1 = rowColumnValue.getCell(0);
            cell1.setCellValue(t.getData01());
//			cell1.setCellStyle(cs1);
//			rowColumnValue.setHeight((short) high);
            Cell cell2 = rowColumnValue.getCell(1);
            cell2.setCellValue(t.getData02());
            Cell cell3 = rowColumnValue.getCell(5);
            cell3.setCellValue(t.getData03());
            Cell cell4 = rowColumnValue.getCell(6);
            cell4.setCellValue(t.getData04());
//			cell2.setCellStyle(cs1);
//			rowColumnValue.setHeight((short) high);
//			Cell cell13 = rowColumnValue.createCell(3);
//			cell13.setCellValue(t.getData03());
//			cell13.setCellStyle(cs1);
        }

        try {
            // 第七步，将文件存到指定位置并打印
            String filest = DateUtils.date2Str(DateUtils.yyyymmddhhmmss);
            String savaPath = upLoadPath;
            String fileurl = "gylc" + username + "/" + filest + "/"+ filest + ".xls";

            File file = new File(savaPath + "/" + "gylc" + username + "/" + filest);
            savaPath = savaPath.replace("D:/","D:/");

            if (!file.exists()) {
                file.mkdirs();// 创建文件根目录
            }
            String outfilePath = savaPath + "/" + fileurl;
            try {
                FileOutputStream fileOutputStream = new FileOutputStream(outfilePath);//指定路径与名字和格式
                wb.write(fileOutputStream);//将数据写出去
                fileOutputStream.close();//关闭输出流
                printUtil.printfile(outfilePath);
            } catch (Exception e) {
                e.printStackTrace();
            }
            System.out.println("----Excle文件已生成------");
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (fileOut != null) {
                try {
                    fileOut.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return result;
    }


//
//	@RequestMapping(value = "/print/wlpz/{username}", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
//	@ResponseBody
//	@ApiOperation(value = "打印物料凭证", notes = "打印物料凭证", httpMethod = "POST", produces = "application/json")
//	public Result<?> print105(@PathVariable("username") String username,@PathVariable("mblnrin") String mblnrin,
//								 @RequestBody printheader printheaderobj) {
//		Result<Uwmsdata> result = new Result<Uwmsdata>();
//		String printname="";
//		OutputStream fileOut = null;
//		hanautil hana = new hanautil();
//		BufferedImage bufferImg = null;
//		Map<String,String>  mblnrmap = new HashMap<>();
//		String codedFileName = null;
//		String deliveryId=mblnrin;
//		String shdh ="";
//		String pzrq = "";//
//		String zdr="";//
//		String pzjcy="";//
//
//		try {
//			StringBuffer sber=new StringBuffer();
//
//			List<SapEkpoFhEntity> listInfoList=(List<SapEkpoFhEntity>) this.systemService.findByProperty(SapEkpoFhEntity.class, "qmRemark6", mblnrin);
//
//			for(SapEkpoFhEntity tt: listInfoList){
//				if(StringUtil.isNotEmpty(tt.getQmRemark6())){
//					if(!mblnrmap.containsKey(tt.getQmRemark6())){
//						mblnrmap.put(tt.getQmRemark6(),tt.getQmRemark6());
//					}
//				}
//			}
//
//			//获取供应商数据
//			String supplierNo= listInfoList.get(0).getLifnr();
//			shdh = listInfoList.get(0).getVbeln();
//			SapLfa1Entity supplier= this.systemService.findUniqueByProperty(SapLfa1Entity.class,"lifnr",supplierNo);
//			if(supplier==null){
//				throw new Exception("供应商数据错误。");
//			}
//			String mblnr = "";
//			int sheeti=0;
////			HSSFWorkbook wb = new HSSFWorkbook();
//			try{
//				Thread.sleep(5000); //1000 毫秒，也就是1秒.
//			}catch (Exception e){
//
//			}
//
//			String url = upLoadPath+"/excelmodel/" +"105.xls";
//			HSSFWorkbook wb  = new HSSFWorkbook(new FileInputStream(url));
//
//
//
//
//
//
//			for (String value : mblnrmap.values()) {
//				sheeti++;
//				mblnr = value;
//				String	tsqlxj = "select t.ebenl,t.ebelp,t.qm_remark5,  t.matnr,t.maktx,t.meins,sum(Cast( t.menge2 as decimal(10,2))) as menge " +
//						"from sap_ekpo_fh as t where t.QM_REMARK6 = ? group by t.ebenl,t.ebelp,t.qm_remark5, t.matnr,t.maktx,t.meins  order by matnr ";
//				List<Map<String, Object>> resulthq = systemService
//						.findForJdbc(tsqlxj, mblnr);
//				pzrq = hana.getBLDAT(mblnr);
//				if(StringUtil.isEmpty(pzrq)){
//					pzrq = DateUtils.date2Str(DateUtils.date_sdf);
//				}
//				zdr = hana.getxblnr(mblnr);
//
//
//				ByteArrayOutputStream byteArrayOut = new ByteArrayOutputStream();
//				bufferImg = QRcodeUtil.createImage(mblnr);
//				ImageIO.write(bufferImg, "jpg", byteArrayOut);
//				HSSFSheet sheet = wb.getSheet("sheet1");
//				sheet.setColumnWidth(0, 5 * 256);
//				sheet.setColumnWidth(1, 12 * 256);
//				sheet.setColumnWidth(2, 30 * 256);
//				sheet.setColumnWidth(3, 5 * 256);
//				sheet.setColumnWidth(4, 5 * 256);
//				sheet.setColumnWidth(5, 8 * 256);
//				sheet.setColumnWidth(6, 6 * 256);
//				sheet.setColumnWidth(7, 12 * 256);
//				sheet.setColumnWidth(8, 6 * 256);
//				sheet.setColumnWidth(9, 12 * 256);
//
//				sheet.setMargin(HSSFSheet.TopMargin,( double ) 0.1 ); // 上边距
//				sheet.setMargin(HSSFSheet.BottomMargin,( double ) 0.1 ); // 下边距
//				sheet.setMargin(HSSFSheet.LeftMargin,( double ) 0.1 ); // 左边距
//				sheet.setMargin(HSSFSheet.RightMargin,( double ) 0.1 ); // 右边距
//
////			String [] columnNamesNew={"序列号","采购订单号","行项","雅瑞物料号","物料描述","单位","送货数量","采购文本","备注"};
//
//
//				//画图的顶级管理器，一个sheet只能获取一个（一定要注意这点）
//				HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
//				//anchor主要用于设置图片的属性
//				HSSFClientAnchor anchor = new HSSFClientAnchor(15, 15, 0, 0,(short) 1, 1, (short) 2, 4);
//				anchor.setAnchorType(3);
//				//插入图片
//				patriarch.createPicture(anchor, wb.addPicture(byteArrayOut.toByteArray(), HSSFWorkbook.PICTURE_TYPE_JPEG));
//				// 创建第一行
//				Row row = sheet.createRow((short) 0);   //第一行空白
//				// 创建两种单元格格式
//				CellStyle cs = wb.createCellStyle();
//				CellStyle csr = wb.createCellStyle();
//				CellStyle cs2 = wb.createCellStyle();
//				CellStyle cs3 = wb.createCellStyle();
//				CellStyle cscenter = wb.createCellStyle();
//				CellStyle cs4 = wb.createCellStyle();
//				Font f4 = wb.createFont();
//
//				f4.setFontHeightInPoints((short) 8);
//				f4.setColor(IndexedColors.BLACK.getIndex());
//				cs4.setFont(f4);
//				cs4.setBorderLeft(CellStyle.BORDER_MEDIUM);
//				cs4.setBorderRight(CellStyle.BORDER_MEDIUM);
//				cs4.setBorderTop(CellStyle.BORDER_MEDIUM);
//				cs4.setBorderBottom(CellStyle.BORDER_MEDIUM);
//				cs4.setAlignment(HSSFCellStyle.ALIGN_LEFT);
//				cs4.setWrapText(true);
//				// 创建两种字体
//				Font f = wb.createFont();
//				Font f10 = wb.createFont();
//				Font f2 = wb.createFont();
//				// 创建第一种字体样式（用于列名）
//				f.setFontHeightInPoints((short) 16);
//				f.setColor(IndexedColors.BLACK.getIndex());
//				f.setBoldweight(Font.BOLDWEIGHT_BOLD);
//				// 创建第一种字体样式（用于列名）
//				f10.setFontHeightInPoints((short) 10);
//				f10.setColor(IndexedColors.BLACK.getIndex());
//				f10.setBoldweight(Font.BOLDWEIGHT_BOLD);
//				// 创建第二种字体样式（用于值）
//				f2.setFontHeightInPoints((short) 10);
//				f2.setColor(IndexedColors.BLACK.getIndex());
//				// 设置第一种单元格的样式（用于列名）
//				cs.setFont(f);
//				cs.setBorderLeft(CellStyle.BORDER_NONE);
//				cs.setBorderRight(CellStyle.BORDER_NONE);
//				cs.setBorderTop(CellStyle.BORDER_NONE);
//				cs.setBorderBottom(CellStyle.BORDER_NONE);
//				cs.setAlignment(HSSFCellStyle.ALIGN_CENTER);
//				csr.setFont(f10);
//				csr.setBorderLeft(CellStyle.BORDER_NONE);
//				csr.setBorderRight(CellStyle.BORDER_NONE);
//				csr.setBorderTop(CellStyle.BORDER_NONE);
//				csr.setBorderBottom(CellStyle.BORDER_NONE);
//				csr.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
//				// 设置第二种单元格的样式（用于值）
//				cs2.setFont(f2);
//				cs2.setBorderLeft(CellStyle.BORDER_NONE);
//				cs2.setBorderRight(CellStyle.BORDER_NONE);
//				cs2.setBorderTop(CellStyle.BORDER_NONE);
//				cs2.setBorderBottom(CellStyle.BORDER_NONE);
//				cs3.setFont(f2);
//				cs3.setBorderLeft(CellStyle.BORDER_MEDIUM);
//				cs3.setBorderRight(CellStyle.BORDER_MEDIUM);
//				cs3.setBorderTop(CellStyle.BORDER_MEDIUM);
//				cs3.setBorderBottom(CellStyle.BORDER_MEDIUM);
//				cs3.setWrapText(true);
//				cscenter.setFont(f2);
//				cscenter.setBorderLeft(CellStyle.BORDER_MEDIUM);
//				cscenter.setBorderRight(CellStyle.BORDER_MEDIUM);
//				cscenter.setBorderTop(CellStyle.BORDER_MEDIUM);
//				cscenter.setBorderBottom(CellStyle.BORDER_MEDIUM);
//				cscenter.setAlignment(CellStyle.ALIGN_CENTER);
//				cscenter.setWrapText(true);
//
//				Cell cellTitlevb = row.createCell(0);
//				cellTitlevb.setCellValue("LM-02-020-S05-M01/V1.0     ");
//				cellTitlevb.setCellStyle(csr);
//				Row row1 = sheet.createRow((short) 1);   //第二行标题
//				row1.setHeight((short)600);
//				Cell cellTitle = row1.createCell(0);
//				cellTitle.setCellValue("厦门雅瑞实业有限公司");
//				cellTitle.setCellStyle(cs);
//				Row rowHead1=sheet.createRow((short) 2);  //头部第一行
//				Cell cellHead11 = rowHead1.createCell(0);
//				cellHead11.setCellValue("采购收货" );
//				cellHead11.setCellStyle(cs);
////			Cell cellHead12 = rowHead1.createCell(4);
////			cellHead12.setCellValue("单号："+mblnr);
////			cellHead12.setCellStyle(cs2);
//				Row rowHead2=sheet.createRow((short) 3);  //头部第二行
//				Cell cellHead21 = rowHead2.createCell(2);
//				cellHead21.setCellValue("");
//				cellHead21.setCellStyle(cs2);
////			Cell cellHead23 = rowHead2.createCell(4);
////			cellHead23.setCellValue("收货公司："+"厦门雅瑞实业有限公司");
////			cellHead23.setCellStyle(cs2);
//
//				Row rowHead3=sheet.createRow((short) 4);  //头部第三行
//				Cell cellHead31 = rowHead3.createCell(0);
//				cellHead31.setCellValue("物料凭证："+mblnr);
//				cellHead31.setCellStyle(cs2);
//
//				Cell cellHead35 = rowHead3.createCell(6);
//				cellHead35.setCellValue("凭证日期："+pzrq);
//				cellHead35.setCellStyle(cs2);
//
//				Row rowHead4=sheet.createRow((short) 5);  //头部第4行
//				Cell cellHead41 = rowHead4.createCell(0);
//				cellHead41.setCellValue("送货单号："+shdh);
//				cellHead41.setCellStyle(cs2);
//				Cell cellHead43 = rowHead4.createCell(6);
//				cellHead43.setCellValue("供应商："+supplier.getName1() );
//				cellHead43.setCellStyle(cs2);
//				//合并单元格
//				CellRangeAddress c = new CellRangeAddress(0, 0, 0, 9);
//				CellRangeAddress   c0 = new CellRangeAddress(1, 1, 0, 9);
//				CellRangeAddress   c111 = new CellRangeAddress(2, 2, 0, 9);
////			CellRangeAddress   c121 = new CellRangeAddress(2, 2, 4, 8);
//				CellRangeAddress   c2 = new CellRangeAddress(3, 3, 0, 9);
////			CellRangeAddress   c3 = new CellRangeAddress(3, 3, 4, 8);
//				CellRangeAddress   c4 = new CellRangeAddress(4, 4, 0, 5);
//				CellRangeAddress   c7 = new CellRangeAddress(4, 4, 6, 9);
//				CellRangeAddress   c8 = new CellRangeAddress(5, 5, 0, 5);
//				CellRangeAddress   c9 = new CellRangeAddress(5, 5, 6, 9);
//				sheet.addMergedRegion(c);
//				sheet.addMergedRegion(c0);
//				sheet.addMergedRegion(c111);
////			sheet.addMergedRegion(c121);
//				sheet.addMergedRegion(c2);
////			sheet.addMergedRegion(c3);
//				sheet.addMergedRegion(c4);
////			sheet.addMergedRegion(c5);
////			sheet.addMergedRegion(c6);
//				sheet.addMergedRegion(c7);
//				sheet.addMergedRegion(c8);
//				sheet.addMergedRegion(c9);
//				Row rowColumnName=sheet.createRow((short) 6);  //列名
//				rowColumnName.setHeight((short)450);
//				String [] columnNamesNew={"序号","物料编码","物料名称","单位","类型","数量","库位","采购订单号","箱号","备注"};
//				int cellsNum=6;
//				int cerconNo=1;
//				Double sumc = 0.00;
//				for(int i=0;i<columnNamesNew.length;i++){
//					Cell cell = rowColumnName.createCell(i);
//					cell.setCellValue(columnNamesNew[i]);
//					cell.setCellStyle(cs3);
//				}
//
//
//				for (int k = 0; k < resulthq.size(); k++) {
//					String bwart = "105";
//					try{
//						pzjcy = resulthq.get(k).get("qm_remark5").toString();
//
//					}catch (Exception e){
//
//					}
//					String MAKTX= "";
//					try {
//						MAKTX = resulthq.get(k).get("maktx").toString();//物料描述
//					}catch (Exception e){
//
//					}
//					String MATNR= "";
//					try{
//						MATNR = resulthq.get(k).get("matnr").toString();
//					}catch (Exception e){
//
//					}
//					String meins="";
//					try{
//						meins = resulthq.get(k).get("meins").toString();
//					}catch (Exception e){
//
//					}
//					String menge="";
//					try{
//						if(StringUtil.isEmpty(resulthq.get(k).get("menge").toString())){
//							continue;
//						}else{
//							menge = resulthq.get(k).get("menge").toString();
//							if(Double.parseDouble(menge)==0.00){
//								continue;
//
//							}
//						}
//					}catch (Exception e){
//						continue;
//					}
//					sumc = sumc+Double.parseDouble(menge);
//					String ebeln = resulthq.get(k).get("ebenl").toString()+"/"+ resulthq.get(k).get("ebelp").toString();
//					String xianghao = "";  //resulthq.get(k).get("xianghao").toString();
//					String chuwei = hana.getlqua(MATNR);
//					cellsNum++;
//					Row rowColumnValue=sheet.createRow((short) cellsNum);  //列名
//					rowColumnValue.setHeight((short)500);
//
//					for(int ci=0;ci<=9;ci++){
//						Cell cell = rowColumnValue.createCell(ci);
//						cell.setCellStyle(cs3);
//
//						if(ci==0){
//							cell.setCellValue(cerconNo);
//							cell.setCellStyle(cscenter);
//
//						}
//						if(ci==1){
//							cell.setCellValue(MATNR);
//
//						}
//						if(ci==2){
//							cell.setCellValue(MAKTX);
//							cell.setCellStyle(cs4);
//						}
//						if(ci==3){
//							cell.setCellValue(meins);
//
//						}
//						if(ci==4){
//							cell.setCellValue(bwart);
//
//						}
//						if(ci==5){
//							cell.setCellValue(Double.parseDouble(menge));
//							cell.setCellStyle(cscenter);
//
//						}
//						if(ci==6){
//							cell.setCellValue("");
//
//						}
//						if(ci==7){
//
//
//							cell.setCellValue(ebeln);
//
//
//
//						}
//						if(ci==8){
//							cell.setCellValue(xianghao);
//
//						}
//
//						if(ci==9){
//							cell.setCellValue(chuwei);
//
//						}
//					}
//
//					cerconNo++;
//				}
//
//				Row rowColumnSum=sheet.createRow((short) 1+cellsNum);  //列名
////			rowColumnSum.setHeight((short)600);
//				Cell cellX10=rowColumnSum.createCell(0);
//				cellX10.setCellValue("总计  :\n\n\n                " +sumc );
//				cellX10.setCellStyle(csr);
//
//				CellRangeAddress   c10 = new CellRangeAddress(1+cellsNum, 1+cellsNum, 0, 8);
//				sheet.addMergedRegion(c10);
//				Row rowColumnSum1=sheet.createRow((short) 2+cellsNum);  //列名
////			rowColumnSum1.setHeight((short)600);
//				Cell cellX1=rowColumnSum1.createCell(0);
//				cellX1.setCellValue("制单人："+zdr+"                            品质检查员："+pzjcy  );
//				CellStyle csX = wb.createCellStyle();
//				csX.setWrapText(true);
//				cellX1.setCellStyle(csX);
//				Cell cellX2= rowColumnSum1.createCell(5);
//				cellX2.setCellValue("审批  :  王学军 " +"       打印日期："+DateUtils.date2Str(DateUtils.date_sdf) );
//				CellRangeAddress   c11 = new CellRangeAddress(2+cellsNum, 2+cellsNum, 0, 4);
//				CellRangeAddress   c12 = new CellRangeAddress(2+cellsNum, 2+cellsNum, 5, 9);
//				sheet.addMergedRegion(c11);
//				sheet.addMergedRegion(c12);
//
//
//			}
//			// 第七步，将文件存到指定位置
//			String filest = DateUtils.date2Str(DateUtils.yyyymmddhhmmss);
//			String savaPath= upLoadPath;
//			String fileurl = deliveryId+  "/"  +filest+  "/105sh" +deliveryId+filest+".xls";
//
//			File file = new File(savaPath +  "/"+deliveryId+  "/"  +filest+  "/105sh" +deliveryId+filest);
//
//
//
//			if (!file.exists()) {
//				file.mkdirs();// 创建文件根目录
//			}
//			String outfilePath = savaPath + "/"+fileurl;
//			try {
//				FileOutputStream fileOutputStream = new FileOutputStream(outfilePath);//指定路径与名字和格式
//				wb.write(fileOutputStream);//将数据写出去
//				fileOutputStream.close();//关闭输出流
//				printname = outfilePath;
//			} catch (Exception e) {
//				e.printStackTrace();
//			}
//
//			printUtil.printfile(printname);
//
//		} catch (Exception e) {
//			e.printStackTrace();
//		}finally{
//			if(fileOut != null){
//				try {
//					fileOut.close();
//				} catch (IOException e) {
//					e.printStackTrace();
//				}
//			}
//		}
//		return result;
//	}
//

    //将byte数组转成16进制字符串
    public  String bytesToHexFun1(byte[] bytes) {
        char[] HEX_CHAR = {'0', '1', '2', '3', '4', '5',
                '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
        // 一个byte为8位，可用两个十六进制位标识
        char[] buf = new char[bytes.length * 2];
        int a = 0;
        int index = 0;
        for(byte b : bytes) { // 使用除与取余进行转换
            if(b < 0) {
                a = 256 + b;
            } else {
                a = b;
            }
            buf[index++] = HEX_CHAR[a / 16];
            buf[index++] = HEX_CHAR[a % 16];
        }
        return new String(buf);
    }

}
